package edu.cueb.wmis.controller;


import edu.cueb.wmis.pojo.Admin;
import edu.cueb.wmis.pojo.Incomebill;
import edu.cueb.wmis.pojo.Incomebillitem;
import edu.cueb.wmis.pojo.RespBean;
import edu.cueb.wmis.service.IAdminService;
import edu.cueb.wmis.service.IIncomebillService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuzizhuo
 * @since 2021-04-19
 */
@RestController
@RequestMapping("/incomebill")
public class IncomebillController {
    @Autowired
    private IIncomebillService iIncomebillService;
    @Autowired
    private IAdminService adminService;
    @ApiOperation(value = "点击入库生成概单")
    @PostMapping("/")
    public RespBean addIncomeBill(@RequestBody Incomebill incomebill){

        if(iIncomebillService.addIncomeBill(incomebill)){

            return RespBean.success("建立入库单成功");
        }else{
            return RespBean.error("建立入库单失败");
        }
    }
    @ApiOperation(value = "获得所有入库概单和详单")
    @GetMapping("/")
    public RespBean getIncomeBillAndItem(){

        List<Incomebill> incomeBillAndItem = iIncomebillService.getIncomeBillAndItem();
        if(incomeBillAndItem != null){
            return RespBean.success("成功返回入库单",incomeBillAndItem);
        }else{
            return RespBean.error("失败!");
        }
    }

    @ApiOperation(value = "返回详单根据入库概单Id")
    @GetMapping("/{inbillId}")
    public RespBean getIncomeItemByBillId(@PathVariable Integer inbillId){
        List<Incomebillitem> incomebillitems  = iIncomebillService.getIncomeItemsByBillId(inbillId);
        if(incomebillitems != null){
            return RespBean.success("成功返回入库单",incomebillitems);
        }else{
            return RespBean.error("失败!");
        }
    }
}
